package com.ldy.netty;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * 入口，负责启动应用
 * @Author 刘德咏
 * @Date 2019/6/2-16:50
 * @Description
 */
public class Main {
    public static void main(String[] args) {
        EventLoopGroup bossGroup = new NioEventLoopGroup();
        EventLoopGroup workGroup = new NioEventLoopGroup();
        try {

            ServerBootstrap sb = new ServerBootstrap();
            sb.group(bossGroup, workGroup);
            sb.channel(NioServerSocketChannel.class);
            sb.childHandler(new MyWebSocketChannelHandler());
            System.out.println("服务器开启等待客户端连接");
            Channel ch = sb.bind(8888).sync().channel();
            ch.closeFuture().sync();

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            bossGroup.shutdownGracefully();
            workGroup.shutdownGracefully();
        }
    }
}
